package com.link.base.base.servicerequest.controller;


import com.link.core.cllog.LCLogger;
import com.link.base.base.servicerequest.model.ServiceRequest;
import com.link.base.base.servicerequest.service.ServiceAcceptService;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;


/**
 * @author unknown
 * @date unknown
 * @comments 服务请求
 */
@Controller
@RequestMapping("/link/serviceAccept")
public class ServiceAcceptController extends BasicController<ServiceRequest> {

    @Resource
    private ServiceAcceptService serviceAcceptService;

    @Override
    public BasicService<ServiceRequest> getBasicService() throws Exception {
        return serviceAcceptService;
    }


    @Override
    public void beforQueryAllOrExample(ServiceRequest record, HttpServletRequest request) {

        record.setModuleType("Service Accept");
    }

    @RequestMapping(value = "/submit", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> submit(ServiceRequest record, HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            serviceAcceptService.submit(record);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
}
